package com.sunlake.spring.main.common.utils;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
/**
 * RabbitMQ工具类
 * 提供发送消息的方法
 * @author by liuhanzhi
 */
@Component
@Slf4j
public class RabbitMQUtils {
    @Autowired
    private RabbitTemplate rabbitTemplate;
    
    // 发送方法，指定交换机、routing key和消息内容
    public void sendMessage(String exchange, String routingKey, Object message) {
        try {
            rabbitTemplate.convertAndSend(exchange, routingKey, message);
            log.info("消息发送成功: exchange={}, routingKey={}", exchange, routingKey);
        } catch (Exception e) {
            log.error("消息发送失败: {}", e.getMessage(), e);
        }
    }
}